package io.huaguoguo.spring.config;

import io.huaguoguo.spring.listener.JudyListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.web.client.RestTemplate;

import java.util.concurrent.Executors;

/**
 * 描述：  <br>
 * CreateDate: 2021/5/28 <br>
 *
 * @author huaguoguo
 */
@Configuration
public class ListenerConfig {

    @Bean
    public SimpleApplicationEventMulticaster applicationEventMulticaster() {
        SimpleApplicationEventMulticaster applicationEventMulticaster = new SimpleApplicationEventMulticaster();
        applicationEventMulticaster.setErrorHandler(e -> {
            System.out.println(Thread.currentThread().getName() + ":" + e.getMessage());
        });
        applicationEventMulticaster.setTaskExecutor(Executors.newFixedThreadPool(10));
        return applicationEventMulticaster;
    }

    @Bean
    public RestTemplate restTemplate(){
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate;
    }

    @Bean(initMethod = "init",destroyMethod = "destroyMethod")
    public JudyListener judyListener(){
        return new JudyListener();
    }
}
